//
//  NSTextAttachmentAdditions.m
//  MailDelivery
//
//  Created by Dante Palacios on 08/09/09.
//  Copyright 2009 Dante Palacios. All rights reserved.
//

#import "NSTextAttachmentAdditions.h"


@implementation NSTextAttachment (MailDeliveryAdditions)

- (NSString *)filename 
{
	NSString *description = [self description];
	if ([description rangeOfString:@"\""].location != NSNotFound)
	{
		NSScanner *scanner = [NSScanner scannerWithString:description];
		NSString *filename = @"";
		@try {
			[scanner scanUpToString:@"\"" intoString:nil];
			[scanner setScanLocation:[scanner scanLocation] + 1];
			[scanner scanUpToString:@"\"" intoString:&filename];	
		}
		@catch (NSException * e) {
			return nil;
		}
		return [filename stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];	
	}
	return nil;
}

@end
